package com.course.server.controller;

import com.course.server.entity.vo.LoginVO;
import com.course.server.service.AdminUserService;
import com.course.server.utils.ResponseResult;
import com.course.server.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;


@RestController
@RequestMapping("/admin/user")
@CrossOrigin
public class AdminUserController {
    @Autowired
    private AdminUserService adminUserService;

    /**
     * @description: TODO 登录
     * @author: 万物皆可喵
     * @date: 2022/9/21 14:40
     * @param: [loginVO]
     * @return: com.course.server.utils.ResponseResult<java.lang.String>
     **/
    @PostMapping("/login")
    public Result<Map<String,Object>> login(@RequestBody LoginVO loginVO) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        if (loginVO==null){
            return Result.noArgs();
        }
        if (loginVO.getUsername() == null || "".equals(loginVO.getUsername())){
            return Result.noArgs();        }
        if (loginVO.getPassword()==null || "".equals(loginVO.getPassword())){
            return Result.noArgs();
        }

        return adminUserService.login(loginVO);
    }

    /**
     * @description: TODO 退出登录
     * @author: 万物皆可喵
     * @date: 2022/9/21 14:48
     * @param: [Authorization]
     * @return: com.course.server.utils.ResponseResult<java.lang.Boolean>
     **/
    @GetMapping("/loginOut")
    public ResponseResult<Boolean> loginOut(@RequestHeader("token") String Authorization ){
        return adminUserService.loginOut(Authorization);
    }
}
